package com.patzn.osgi.listener;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;

public class ServiceListenerActivator implements BundleActivator {
    @Override
    public void start(BundleContext bundleContext) throws Exception {
        bundleContext.addServiceListener(new ServiceListener() {
            @Override
            public void serviceChanged(ServiceEvent serviceEvent) {
                System.out.println("服务事件[start]：" + serviceEvent.getSource() + ":" + serviceEvent.getType());
            }
        });
    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {
        bundleContext.addServiceListener(new ServiceListener() {
            @Override
            public void serviceChanged(ServiceEvent serviceEvent) {
                System.out.println("服务事件[stop]：" + serviceEvent.getSource() + ":" + serviceEvent.getType());
            }
        });
    }
}
